import QtQuick 1.1
import com.nokia.symbian 1.1

Page {
    id: mainPage
    tools: ToolBarLayout {
        ToolButton {
            flat: true
            iconSource: "toolbar-back"
            onClicked: Qt.quit()
        }
    }

    Rectangle {
        id: board
        color: "moccasin"
        anchors.fill: parent

        property variant elementSize: Qt.rect(0, 0, 10, 10)
        property variant lastRecord: Qt.point(0,0)

        function updateposition(){
            if ((Math.abs(board.lastRecord.x - mouse.mouseX) < board.elementSize.x) ||
                    (Math.abs(board.lastRecord.y - mouse.mouseY) < board.elementSize.y)){
                return;
            }

            Qt.createQmlObject(
                        'import QtQuick 1.0; ' +
                        'Rectangle {color: "brown"' +
                        '; width: ' + board.elementSize.width +
                        '; height: ' + board.elementSize.height +
                        '; x: ' + mouse.mouseX +
                        '; y: ' + mouse.mouseY + '}',board);
        }

        MouseArea {
            id: mouse
            anchors.fill: parent

            onPressed: {
                cmdRepeatTimer.running = true;
            }
            onReleased: {
                cmdRepeatTimer.running = false;
            }
        }

        Timer {
            id: cmdRepeatTimer
            interval: 5; running: false; repeat: true
            onTriggered: board.updateposition()
        }
    }
}
